﻿using Common.UGUI.View;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 这个类有点炫技（对C#和Unity，以及面向对象的熟悉程度)，只是为了试试abstract特性。。。。。
/// </summary>
public abstract class ObjectReference : MonoBehaviour {
	public GameObject[] objs;
	[Header("按钮会自动注册事件（Custom)")]
	public Object[] objSubs;
	public GameObject Get(int index)
	{
		if (objs.Length <= index) return null;
		return objs[index];

	}
	//public UDropdown GetDropdown(int index)
	//{
	//	var o = GetObject(index) as GameObject;
	//	if (o != null)
	//		return new UDropdown(o);
	//	else
	//		return null;
	//}
	//public UGUIButton GetButton(int index)
	//{
	//	var o = GetObject(index) as GameObject;
	//	if (o != null)
	//		return new UGUIButton(o);
	//	else
	//		return null;
	// }
	public Object GetObject(int index)
	{
        
		if (objSubs.Length <= index) return null;
		return objSubs[index];
	}
	/// <summary>
	/// 启动会变慢，待解决（TODO:这个点，不开玩笑，真的需要争分夺秒）
	/// </summary>
	protected virtual void  Start () {
		foreach (var obj in objSubs)
		{
			GameObject go = obj as GameObject;
			if (go != null)
			{
				Button btn = go.GetComponent<Button>();
				if (btn != null)
					EventTriggerListener.Get(btn).onClick += OnButtonClick;
			}
		}
	}

	protected abstract void OnButtonClick(GameObject sender);

}
